#include <iostream>
#include <fstream>
#include <string>
#include <ctime>

using namespace std;

int main(int argc, char *argv[])
{
	srand((unsigned)time(0));
	ifstream in("input.txt");
	ofstream out("result.txt");
	ofstream out2("resultbgc.txt");
	int width=atoi(argv[1]), height=atoi(argv[2]);
	int n;
	in>>n;
	for (int i=0;i<n;i++)
	{
		string src, title, captain, rotate;
		in>>src>>title>>captain>>rotate;
		int aw=width, ah=height;
		if (rotate=="1")
		{
			aw=height;
			ah=width;
		}
		out<<"\n\n[caption id=\"\" align=\"alignnone\" width=\""<<aw<<"\" caption=\""<<captain<<"\"]<img class=\" \" title=\""<<title<<"\" src=\""<<src<<"\" alt=\""<<captain<<"\" width=\""<<aw<<"\" height=\""<<ah<<"\" />[/caption]";
		out2<<"[img]"<<src<<"[/img]\n"<<captain<<"\n";
	}
	in.close();
	out.close();
	out2.close();
	return 0;
}